package com.wechat.back.mapper;

import com.wechat.back.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from user where username=#{username}")
    User findByUserName(String username);

    @Insert("insert into user(username,password,user_power,hobby,create_time,update_time)" +
    " values(#{username},#{password},#{userPower},#{hobby},now(),now())")
    void add(String username, String password ,Integer userPower);

    @Update("update user set username=#{username},nickname=#{nickname},sex=#{sex},locate=#{locate},phone=#{phone},email=#{email},hobby=#{hobby},user_pic=#{userPic}, update_time=#{updateTime} " +
            " where id=#{id}")
    void update(User user);

    @Update("update user set user_status=#{userStatus} where id=#{id}")
    void updateStatus(Integer id, String userStatus);

    @Update("update user set user_power=#{userPower} where id=#{id}")
    void updatePower(Integer id, Integer userPower);

    @Update("update user set user_pic=#{avatarUrl}, update_time=now()" +
            " where id=#{id}")
    void updateAvatar(String avatarUrl, Integer id);

    @Update("update user set password=#{password},update_time=now() where id=#{id}")
    void updatePwd(String password, Integer id);

    List<User> list(String username);

    @Select("select * from user where id=#{id}")
    User findById(Integer id);
}
